import diseaseInfoComponent from "./disease/disease_info_com.js";
import indexComponent from "../pages/index_com.js"
import userLoginComponent from "../pages/user/user_login_com.js"
import doctorComponent from "./doctor/doctor_login_com.js"
import userMainComponent from "./user/user_main_com.js";
import registerComponent from "./user/register_com.js";
import workInfoComponent from "./doctor/work_info_com.js";
import registerInfoComponent from "./user/register_info_com.js";
import doctorMainComponent from "./doctor/doctor_main_com.js";
import newAccountComponent from "./new_account_com.js";
import caseInfoComponent from "./case/case_info_com.js"
import topicInfoComponent from "./topic/topic_info_com.js";
import topicReplyComponent from "./topic/topic_reply_com.js";

const app = Vue.createApp({
    setup() {

    },
})


//防止中文乱码
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8'

const router = VueRouter.createRouter({
    history: VueRouter.createWebHashHistory(),
    routes: [
        {path: '/', component: indexComponent},
        {path: '/new_account', component: newAccountComponent},
        {path: '/user/', component: userLoginComponent},
        {path: '/doctor/', component: doctorComponent},
        {path: '/disease/:id', component: diseaseInfoComponent, props: true},
        {path: '/user_main/:id', component: userMainComponent, props: true},
        {path: '/register/:id', component: registerComponent, props: true},
        {path: '/work_info/:id', component: workInfoComponent, props: true},
        {path: '/register_info/:id', component: registerInfoComponent, props: true},
        {path: '/doctor_main/', component: doctorMainComponent},
        {path: '/case_info/:id', component: caseInfoComponent, props: true},
        {path: '/topic_info/:pageNum', component: topicInfoComponent, props: true},
        {path: '/topic_reply/:id/:pageNum', component: topicReplyComponent, props: true},
    ], // `routes: routes` 的缩写
});
router.afterEach((to, from) => {
    const toStr = to.fullPath;
    const fromStr = from.fullPath;
    if ((toStr.startsWith("/topic_info") && fromStr.startsWith("/topic_info"))
        || (toStr.startsWith("/topic_reply") && fromStr.startsWith("/topic_reply"))) {
        router.go(0);
    }
});
app.use(router);
app.mount("#app");